$(function () {
    $("#add-boards-btn").click(function (event) {
        event.preventDefault();
        xtalert.alertOneInput({
            "title": "请输入模块名",
            "placeholder": "模块名",
            "confirmCallback": function (inputValue) {
                zlajax.post({
                    "url": "/cms/aboards/",
                    "data": {
                        "name": inputValue
                    },
                    "success": function (data) {
                        if (data["code"] == 200) {
                            window.location.reload()
                        } else {
                            xtalert.alertInfoToast(data["message"])
                        }
                    }
                })
            }
        })
    })
})


$(function () {
    $(".save-board-btn").click(function (event) {
        event.preventDefault();
        var self = $(this);
        var tr = self.parent().parent();
        var name = tr.attr("data-name");
        var board_id = tr.attr("data-id");

        xtalert.alertOneInput({
            "title": "请输入新的板块名字",
            "placeholder": name,
            "confirmCallback":function (inputValue) {
                zlajax.post({
                    "url": "/cms/uboards/",
                    "data": {
                        "board_id" :board_id,
                        "name": inputValue
                    },
                    "success":function (data) {
                        if(data["code"]==200){
                            window.location.reload()
                        }else{
                            xtalert.alertInfoToast(data["message"])
                        }
                    }
                })
            }
        })
    })
})


$(function () {
    $(".delete-board-btn").click(function (event) {
        event.preventDefault();
        var self = $(this)
        var tr = self.parent().parent();
        var board_id = tr.attr("data-id");
        xtalert.alertConfirm({
            "msg": "您确定删除模块吗？",
            "confirmCallback":function () {
                zlajax.post({
                    "url":"/cms/dboards/",
                    "data":{
                        "board_id": board_id
                    },
                    "success":function (data) {
                        if(data["code"]==200){
                            window.location.reload()
                        }else{
                            xtalert.alertInfoToast(data["message"])
                        }
                    }
                })
            }
        })
    })
})